package com.zzyl.nursing.controller;

import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.NursingTaskDto;
import com.zzyl.nursing.dto.NursingTaskQueryDto;
import com.zzyl.nursing.dto.TaskDto;
import com.zzyl.nursing.dto.CancelDto;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.vo.NursingTaskVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/nursing/nursingTask")
public class NursingTaskController {

    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 根据护理任务查询条件获取护理任务列表。
     *
     * @param nursingTaskQueryDto 包含查询条件的护理任务查询数据传输对象。
     * @return 返回包含护理任务信息的TableDataInfo对象。
     * 取消任务
     */
    @GetMapping("/list")
    public TableDataInfo list(NursingTaskQueryDto nursingTaskQueryDto) {
        TableDataInfo task = nursingTaskService.findTask(nursingTaskQueryDto);
        return task;
    }

    @PutMapping("updateTime")
    public AjaxResult updateTime(@RequestBody TaskDto dto) {
        nursingTaskService.updateTime(dto);
        return AjaxResult.success();
    }
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody CancelDto dto) {
        nursingTaskService.cancel(dto);
        return AjaxResult.success();
    }

    /**
     * 执行护理任务。
     *
     * @param dto 包含护理任务详细信息的NursingTaskDto对象。
     * @return 返回执行成功的AjaxResult对象。
     */
    @PutMapping("/do")
    public AjaxResult todoTask(@RequestBody NursingTaskDto dto) {
        nursingTaskService.todoTask(dto);
        return AjaxResult.success();
    }

    @GetMapping("/{id}")
    public AjaxResult todoTask(@PathVariable Long id) {
        NursingTaskVo nursingTaskVo = nursingTaskService.showDataInfo(id);
        return AjaxResult.success(nursingTaskVo);
    }
}
